package com.cyy.demo.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Lists;

import java.util.List;

public class Page <T> {
    private java.lang.String requestId;
    private java.lang.Integer currentPage;
    private java.lang.Integer pageSize;
    private java.lang.Integer pageTotal;
    private java.util.List<T> list;
    private java.lang.Integer total;

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(Integer pageTotal) {
        this.pageTotal = pageTotal;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public static void main(String[] args) {

        Page<User1> page = new Page<>();
        User1 user1 = new User1();
        user1.setUsername("aaa");
        User1 user2 = new User1();
        user2.setUsername("bbb");
        List<User1> list = Lists.newArrayList(user1,user2);
        page.setList(list);

        Object o = page;
        String s = JSON.toJSONString(o);
        JSONObject jsonObject = JSON.parseObject(s);
        JSONArray list1 = jsonObject.getJSONArray("list");
        List<User1> user1s = list1.toJavaList(User1.class);
        for (User1 user11 : user1s) {
            System.out.println(user11.getUsername());
        }

        Page<User1> page2 = JSON.parseObject(s, new TypeReference<Page<User1>>() {
        }.getType());
        System.out.println(page2);
    }

}
